package org.brownflat.lighthouse.util;

import org.apache.log4j.Logger;

import java.io.IOException;
import java.io.InputStream;

/**
 * <p>&copy Rupert Jones 2012</p>
 *
 * @author rup
 */
public class StringUtil {
    private final static Logger LOG = Logger.getLogger(StringUtil.class);

    public static String toString(InputStream in) {
        try {
            StringBuilder out = new StringBuilder();
            byte[] b = new byte[4096];
            for (int n; (n = in.read(b)) != -1; ) {
                out.append(new String(b, 0, n));
            }
            return out.toString();
        } catch (IOException ioe) {
            LOG.error(ioe);
            return null;
        }
    }
}
